package com.example.util;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * SharePreference工具类
 */
public class SharePreferenceUtils {
    private static final String PERENCE_NAME = "TroopSetting";

    public static String getString(Context context, String key, String defaultValue) {
        SharedPreferences sp = context.getSharedPreferences(PERENCE_NAME, Context.MODE_PRIVATE);
        return sp.getString(key, defaultValue);
    }

    public static void putString(Context context, String key, String value) {
        SharedPreferences sp = context.getSharedPreferences(PERENCE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putString(key, value);
        editor.commit();
    }

    public static void removeValue(Context context, String key) {
        SharedPreferences sp = context.getSharedPreferences(PERENCE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.remove(key);
        editor.commit();
    }
}
